// formValidate  currencyRules
// 输入验证 不允许空格
export function validateText(rule, value, callback) {
  if (value.trim() !== '') {
    callback()
  } else {
    callback(new Error('请输入有效字符 空格无效'))
  }
}
export function validateNumber(rule, value, callback) {
  const valid = new RegExp('^[0-9]*$')
  if (valid.test(value)) {
    callback()
  } else {
    callback(new Error('只能输入数字'))
  }
}
export function validateIp(rule, value, callback) {
  const reg = new RegExp(
    '^((25[0-5]|2[0-4]\\d|[1]{1}\\d{1}\\d{1}|[1-9]{1}\\d{1}|\\d{1})($|(?!\\.$)\\.)){4}$'
  )
  if (reg.test(value)) {
    callback()
  } else {
    callback(new Error('请输入正确的ip地址'))
  }
}

export function validatenumEng(rule, value, callback) {
  const reg1 = new RegExp('^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{4,30}$')
  if (reg1.test(value)) {
    callback()
  } else {
    callback(new Error('请输入数字和英文的组合'))
  }
}
export default {
  // 常用输入验证
  // text: [{ required: true, validator: validateText, trigger: 'blur' }]
  text: [
    { required: true, message: '请输入信息', trigger: 'blur' },
    { min: 2, max: 18, message: '输入字符长度在2到18之间', trigger: 'blur' },
    { validator: validateText, trigger: 'blur' }
  ],
  port: [
    { required: true, message: '请输入tcp端口号', trigger: 'blur' },
    { validator: validateNumber, trigger: 'blur' }
  ],
  portName: [
    { required: true, message: '请输入RTU串口名', trigger: 'blur' },
    { validator: validatenumEng, trigger: 'blur' }
  ],
  host: [
    { required: true, message: '请输入TCP 地址', trigger: 'blur' },
    { validator: validateIp, trigger: 'blur' }
  ]
}
